<?php


namespace app\common\validate;


class CartValidate extends CommonValidate
{
    protected $rule    = [
        'id|ID'                 => 'require|integer|between:1,100000000',
        'ids|购物车IDS'            => 'require|enumIds',
        'cart_id|购物车ID'         => 'require|integer|between:1,100000000',
        'cart_ids|购物车IDS'       => 'require|enumIds',
        'product_id|商品ID'       => 'require|integer|between:1,100000000',
        'product_sku_id|商品库存ID' => 'require|integer|between:1,100000000',
        'count|商品库存数量'          => 'require|integer',
    ];
    protected $message = [];
    protected $scene   = [
        'getCartByIds' => [
            'cart_ids',
        ],
        'postCart'     => [
            'product_id',
            'product_sku_id',
            'count',
        ],
        'putCart'      => [
            'cart_id',
            'product_id',
            'product_sku_id',
            'count',
        ],
        'deleteCart'   => ['cart_ids'],
    ];
    //
    //    /**
    //     * @param $value
    //     * @return bool
    //     */
    //    protected function postCartInfo($value): ?bool
    //    {
    //        try {
    //            if (!array_key_exists('product_id', $value) || !array_key_exists('product_sku_id', $value) || !array_key_exists('count', $value)) {
    //                return false;
    //            }
    //
    //            if (!(false !== filter_var($value['product_id'], FILTER_VALIDATE_INT)) || !(false !== filter_var($value['product_sku_id'], FILTER_VALIDATE_INT)) || !(false !== filter_var($value['count'], FILTER_VALIDATE_INT))) {
    //                return false;
    //            }
    //            return true;
    //        } catch (\Exception $e) {
    //            return false;
    //        }
    //    }
}